package com.wt.easyadmin.service.bussiness.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import com.github.pagehelper.PageHelper;
import com.wt.easyadmin.common.base.PageResultSet;
import com.wt.easyadmin.mapper.bar.TBarCashOutMapper;
import com.wt.easyadmin.model.bar.TBarCashOut;
import com.wt.easyadmin.service.bussiness.CashOutService;

import tk.mybatis.mapper.weekend.Weekend;
import tk.mybatis.mapper.weekend.WeekendCriteria;

@Service
public class CashOutServiceImpl implements CashOutService {

	@Autowired
	private TBarCashOutMapper tBarCashOutMapper;
	
	@Override
	public PageResultSet<TBarCashOut> findByCashOutUser(TBarCashOut tBarCashOut) {
		PageHelper.offsetPage(tBarCashOut.getOffset(), tBarCashOut.getLimit());
        if(!StringUtils.isEmpty(tBarCashOut.getOrderBy())) {
            PageHelper.orderBy(tBarCashOut.getOrderBy());
        }      
        Weekend<TBarCashOut> weekend = Weekend.of(TBarCashOut.class);
        WeekendCriteria<TBarCashOut, Object> criteria = weekend.weekendCriteria();
        if (!StringUtils.isEmpty(tBarCashOut.getCashOutUser())) {
        	criteria.andEqualTo(TBarCashOut::getCashOutUser,tBarCashOut.getCashOutUser());        	
        }
        PageResultSet<TBarCashOut> resultSet = new PageResultSet<>();	
        List<TBarCashOut> list = tBarCashOutMapper.selectByExample(weekend);
        long count = tBarCashOutMapper.selectCountByExample(weekend);
        resultSet.setRows(list);
        resultSet.setTotal(count);
		return resultSet;
	}

}
